<?php $this->placeholder('big-section-class')->set('grid_12 main_section') ?>
<?php $this->JQuery()->javascriptCaptureStart()?>
var uploader;

$j('#tips1').tipsy({gravity: 'w', html: true, fallback: "<p style='text-align:left'><?php echo $this->t('Your profile photo will be displayed in Poster Profile & Ad Detail pages if you are a Premium Account owner')?></p>" });
$j('#tips2').tipsy({gravity: 'w', html: true, fallback: "<p style='text-align:left'><?php echo $this->t('Please detail your area of expertise and service focus.<br>Example: Your sales focus is luxury apartments for rent or European<br>import vehicles for sale.')?></p>" });
$j('#tips3').tipsy({gravity: 'w', html: true, fallback: "<p style='text-align:left'><?php echo $this->t('Your name will be displayed in:<br>1. Poster Profile page<br>2. Ad Detail Page')?></p>" });
$j('#tips4').tipsy({gravity: 'w', html: true, fallback: "<p style='text-align:left'><?php echo $this->t('Agent License # is required information<br>when posting Property and Car Ads')?></p>" });

$j(document).ready(function(){
    $j('a.change').each(function() {
        $j(this).click(function() {
            var div = $j(this).attr('rel');
            if (div == 'profile_photo') {
                $j('#change_photo').toggle();
                $j('#hide_photo').toggle();
            }
            if (div == 'profile_name') {
                $j('#change_name').toggle();
                $j('#hide_name').toggle();
            }
            if (div == 'profile_phone') {
                $j('#change_phone').toggle();
                $j('#hide_phone').toggle();
            }
            if (div == 'profile_license') {
                $j('#change_license').toggle();
                $j('#hide_license').toggle();
            }
            if (div == 'profile_location') {
                $j('#change_location').toggle();
                $j('#hide_location').toggle();
            }
            if (div == 'profile_services') {
                $j('#change_services').toggle();
                $j('#hide_services').toggle();
            }
            $j('#'+div).toggle(function() {
                if (div == 'profile_photo') {
                    setTimeout(function() {
                        uploader.init();
                        uploader.bind('FilesAdded', function(up, files) {
                            uploader.start();
                        });
                    },200);
                }
            });
            $j('#'+div).parent().find('.info').toggle();
            return false;
        });
    });
});


$j(document).ready(function() {
	uploader = new plupload.Uploader({
		runtimes : 'html5,flash,html4',
		browse_button : 'pickfiles',
		container : 'container_uploader',
		max_file_size : '10mb',
		url : '/default/upload/company-pic',
		flash_swf_url : '/plupload/js/plupload.flash.swf',
		silverlight_xap_url : '/plupload/js/plupload.silverlight.xap',
		filters : [
			{title : "Image files", extensions : "jpeg,jpg,gif,png"},
			{title : "Zip files", extensions : "zip"}
		],
		resize : {width : 320, height : 240, quality : 90}
	});

	uploader.bind('Error', function(up, err) {
		$j('#filelist').append("<div>Error: " + err.code +
			", Message: " + err.message +
			(err.file ? ", File: " + err.file.name : "") +
			"</div>"
		);

		up.refresh(); // Reposition Flash/Silverlight
	});

	uploader.bind('FileUploaded', function(up, file, res) {
        var response = $j.parseJSON(res.response);
		$j('#' + file.id + " b").html("100%");
        //var img = $j('img').attr("src",response.url).html();
        $j('#profile_pic_cnt').empty();
        $j(document.createElement("img"))
            .attr({ src: response.url, rel:response.ori, id:'profile_pic_to_be'})
            .appendTo($j('#profile_pic_cnt'))

        $j.ajax({
            type: 'POST',
            url: '<?php echo $this->geturl('confirm-profile-pic', 'user')?>',
            data: {url:response.ori, 'type':'company'},
            success:function () {
                $j('#holder_pic').attr('src',response.url);
            }
        });
	});

	// Client side form validation
	$j('#form_uploader').submit(function(e) {
		var uploader = $j('#uploader').pluploadQueue();

		// Validate number of uploaded files
		if (uploader.total.uploaded == 0) {
			// Files in queue upload them first
			if (uploader.files.length > 0) {
				// When all files are uploaded submit form
				uploader.bind('UploadProgress', function() {
					if (uploader.total.uploaded == uploader.files.length)
						$j('form').submit();
				});

				uploader.start();
			} else
				alert('<?php echo $this->t('You must at least upload one file.')?>');

			e.preventDefault();
		}
	});


    $j('#profile_name_form').submit(function(e) {
        if ( ($j('#profile_firstname').attr('value') != '') &&
             ($j('#profile_lastname').attr('value') != '') &&
             ($j('#profile_username').attr('value') != '')
           )
       {
            $j.post(
                '<?php echo $this->geturl('account-holder-name','user')?>',
                $j('#profile_name_form').serialize(),
                function (data) {
                    if (data != 1) {
                        $j('#un_error1').html("'" + $j('#profile_username').attr('value') + "' is already taken");
                        $j('#profile_username').attr('value', '');
                        $j('#un_error1').show();
                    }
                    else {
                        $j('#updated_message').show().delay(4000).fadeOut();
                        $j('#profile_name_name').html($j('#profile_firstname').attr('value')+ ' ' + $j('#profile_lastname').attr('value'));
                        $j('#profile_username_name').html($j('#profile_username').attr('value'));
                        $j('#profile_name').parent().find('.info').toggle();
                        $j('#profile_name').toggle();
                        $j('#change_name').toggle();
                        $j('#hide_name').toggle();
                        $j('#fn_error').hide();
                        $j('#ln_error').hide();
                        $j('#un_error').hide();
                        $j('#un_error1').hide();
                        $j('#un_error2').hide();
                    }
                }
            );
        }
        else {
            if ($j('#profile_firstname').attr('value') == '') { $j('#fn_error').show(); } else { $j('#fn_error').hide(); }
            if ($j('#profile_lastname').attr('value') == '') { $j('#ln_error').show(); } else { $j('#ln_error').hide(); }
            if ($j('#profile_username').attr('value') == '') { $j('#un_error').show(); } else { $j('#un_error').hide(); }
        }
        return false;
    });

    $j('#profile_phone_form').submit(function(e) {
        if (($j('#profile_phone_value').attr('value').match(/^\d+$/) != null) || ($j('#profile_phone_value').attr('value') == ''))
        {
            $j.post(
                '<?php echo $this->geturl('account-holder-phone','user')?>',
                $j('#profile_phone_form').serialize(),
                function (data) {
                    if ($j('#profile_phone_value').attr('value') != '') {
                        $j('#profile_phone_name').html($j('#profile_phone_value').attr('value'));
                    }
                    else {
                        $j('#profile_phone_name').html('<?php echo $this->t('No Information')?>');
                    }
                    $j('#updated_message').show().delay(4000).fadeOut();
                    $j('#profile_phone').toggle();
                    $j('#profile_phone').parent().find('.info').toggle();
                    $j('#change_phone').toggle();
                    $j('#hide_phone').toggle();
                    $j('#ph_error').hide();
                }
            );
        }
        else {
            if ($j('#profile_phone_value').attr('value').match(/^\d+$/) == null) { $j('#ph_error').show(); } else { $j('#ph_error').hide(); }
        }
        return false;
    });


    $j('#profile_license_form').submit(function(e) {
        if (($j('#profile_license_value').attr('value').match(/^\d+$/) != null) || ($j('#profile_license_value').attr('value') == ''))
        {
            $j.post(
                '<?php echo $this->geturl('account-holder-license','user')?>',
                $j('#profile_license_form').serialize(),
                function (data) {
                    if ($j('#profile_license_value').attr('value') != '') {
                        $j('#profile_license_name').html($j('#profile_license_value').attr('value'));
                    }
                    else {
                        $j('#profile_license_name').html('<?php echo $this->t('No Information')?>');
                    }
                    $j('#updated_message').show().delay(4000).fadeOut();
                    $j('#profile_license').toggle();
                    $j('#profile_license').parent().find('.info').toggle();
                    $j('#change_license').toggle();
                    $j('#hide_license').toggle();
                }
            );
        }
        else {
            if ($j('#profile_license_value').attr('value').match(/^\d+$/) == null) { $j('#li_error').show(); } else { $j('#li_error').hide(); }
        }
        return false;
    });

    $j('#profile_services_form').submit(function(e) {        
        $j.post(
            '<?php echo $this->geturl('account-holder-services','user')?>',
            $j('#profile_services_form').serialize(),
            function (data) {
            	if ($j('#profile_services_value').attr('value') != '') {
                    $j('#profile_services_name').html($j('#profile_services_value').attr('value'));
                }
                else {
                    $j('#profile_services_name').html('<?php echo $this->t('No Information')?>');
                }
                $j('#updated_message').show().delay(4000).fadeOut();
                $j('#profile_services').toggle();
                $j('#profile_services').parent().find('.info').toggle();
                $j('#change_services').toggle();
                $j('#hide_services').toggle();
            }
        );
        return false;
    });
});
<?php $this->JQuery()->javascriptCaptureEnd()?>
<?php $this->JQuery()->addJavascriptFile('http://bp.yahooapis.com/2.4.21/browserplus-min.js')?>

    <?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/plupload/plupload.v-'.AC_VERSION.'.js'))?>
    <?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/plupload/plupload.html5.v-'.AC_VERSION.'.js'))?>
    <?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/plupload/plupload.html4.v-'.AC_VERSION.'.js'))?>

    <?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/plupload/jquery.plupload.queue.min.v-'.AC_VERSION.'.js'))?>
<?php if (IS_LIVE):?>
    <?php $this->headLink()->appendStylesheet(Ac_Util::getImageBaseUrl('/css/plupload/plupload.queue.v-'.AC_VERSION.'.css'))?>
<?php endif;?>
<?php $this->jQuery()->uiEnable()?>
<?php echo $this->partial('index/my-account-side.phtml', array('select'=> 'profile')) ?>
<?php $this->placeholder('container-class')->set('my_acc profile company setting')?>
<section class="setting grid_9">
    <h2>
        <span><?php echo $this->t('Profile')?></span> 
        <!--a href="<?php echo $this->geturl('my-account-profile','user')?>"><?php echo $this->t('Company')?></a>
        <a href="<?php echo $this->geturl('my-account-profile','user', null, null, array('type' => 'holder'))?>" class="selected"><?php echo $this->t('Account Owner')?></a-->
    </h2>
    <p id="updated_message" class="alert success alert_success hide"><?php echo $this->t('Your Information has been updated')?></p>    
    <dl id="holder_logo">
        <dt><span><?php echo $this->t('Profile Photo')?><a href="#" id="tips1">(Explain)</a></span> <a href="#" rel="profile_photo" class="change" id="change_photo"><?php echo $this->t('Change')?></a><a href="#" rel="profile_photo" class="change" id="hide_photo" style="display:none;"><?php echo $this->t('Hide')?></a></dt>
        <dd class="info"><span><?php echo $this->t('Your Profile Photo')?></span> </dd>
        <dd style="display:none;" id="profile_photo">
            <form>      
				<fieldset>       
                    <div id="container_uploader" style="position: relative;margin-left:0px;margin-right: 0px;padding-right: 0px;">
                        <div class="photo desc">
							<img src="<?php echo $this->thumbnail()->scale($this->loggedin_user->profile_picture, 280, 280);?>" id="holder_pic">
						</div>
                        <div class="file text button company_logo">
	                        <label>Company Logo</label>
						    <span>JPG, GIF or PNG format, size limit 2MB</span>
							<input type="text"><button type="button" id="pickfiles"><?php echo $this->t('Browse')?></button>
						</div>
                        <div class="desc">
							<?php echo $this->t('I certify that I have the right to distribute this picture and that it does not violate the <a href="'.$this->geturl('term-of-use','default',null,'default1').'">Terms of Use</a>.')?>
                        </div>
                        <div class="button em">
                            <button><?php echo $this->t('Update')?></button>
                        </div>
                    </div>     
				</fieldset>          
            </form>           
        </dd>
    </dl>
    
    <dl id="holder_name">
        <dt><span><?php echo $this->t('Name')?><a href="#" id="tips3">(Explain)</a></span> <a href="#" rel="profile_name" class="change" id="change_name"><?php echo $this->t('Change')?></a><a href="#" rel="profile_name" class="change" id="hide_name" style="display:none;"><?php echo $this->t('Hide')?></a> </dt>
        <dd class="info"><span><?php echo $this->t('Your Real Name')?></span><em id="profile_name_name">
		 <?php
        if ((empty($this->loggedin_user->firstname)) && (empty($this->loggedin_user->firstname))) {
            echo $this->t('No Information');
        }
        else {
            echo $this->t($this->loggedin_user->firstname.' '.$this->loggedin_user->lastname);
        }?>
		</em></dd>
        <dd class="info" id="infos_names2"><span><?php echo $this->t('Your Display Name')?></span>&nbsp;<em id="profile_username_name"><?php echo $this->loggedin_user->username?></em></dd>
        <dd style="display:none;" id="profile_name">
            <form id="profile_name_form">
            	<div class="required"><?php echo $this->t('Required')?></div>
                <fieldset>
                    <div class="first_name text col_2">
                        <label class="required"><?php echo $this->t('First Name')?></label>
                        <input type="text" id="profile_firstname" name="firstname" value="<?php echo $this->loggedin_user->firstname?>">
                        <ul class="errors" style="display:none;" id="fn_error"><li><?php echo $this->t('This information is required')?></li></ul>                                
                    </div>     
					<div class="last_name text col_2">
						<label class="required"><?php echo $this->t('Last Name')?></label>
                        <input type="text" id="profile_lastname" name="lastname" value="<?php echo $this->loggedin_user->lastname?>">
                        <ul class="errors" style="display:none;" id="ln_error"><li><?php echo $this->t('This information is required')?></li></ul>
                    </div>    
                    <div class="text">
                        <label style="color:#009900"><?php echo $this->t('Display Name')?></label>
                        <input type="text" id="profile_username" name="username" value="<?php echo $this->loggedin_user->username?>">
                        <ul class="errors" style="display:none;" id="un_error"><li><?php echo $this->t('This information is required')?></li></ul>
                        <ul class="errors" style="display:none;" id="un_error1"><li></li></ul>
                        <ul class="errors" style="display:none;" id="un_error2"><li><?php echo $this->t('4 - 30 character limit')?></li></ul>
                    </div>  
                    <div class="button em"><button type="submit"><?php echo $this->t('Update')?></button></div>
                </fieldset>
            </form>
        </dd>
    </dl>

    <dl id="holder_phone">
        <dt><?php echo $this->t('Phone')?> <a href="#" rel="profile_phone" class="change" id="change_phone"><?php echo $this->t('Change')?></a><a href="#" rel="profile_phone" class="change" id="hide_phone" style="display:none;"><?php echo $this->t('Hide')?></a> </dt>
        <dd class="info" id="infos_phone"><span><?php echo $this->t('Your Mobile Number')?></span><em id="profile_phone_name">
            <?php
            if (empty($this->loggedin_user->phone)) {
                echo $this->t('No Information');
            }
            else {
                echo $this->t($this->loggedin_user->phone);
            }?></em></dd>
        <dd style="display:none;" id="profile_phone">
            <form id="profile_phone_form">
                <fieldset>
                    <div class="text">
                        <label for="profile_phone">
                            <?php echo $this->t('Mobile Phone')?>
                        </label>
                        <input type="text" id="profile_phone_value" name="phone" value="<?php echo $this->loggedin_user->phone?>">
                        <ul class="errors" style="display:none;" id="ph_error"><li><?php echo $this->t('Numbers Only')?></li></ul>
                        <ul class="errors" style="display:none;" id="ph_error1"><li><?php echo $this->t('This information is required')?></li></ul>
                        <ul class="errors" style="display:none;" id="ph_error2"><li><?php echo $this->t('Numbers Only')?></li></ul>
                    </div>
                    <div class="button em"><button type="submit"><?php echo $this->t('Update')?></button></div>
                </fieldset>
             </form>
        </dd>
    </dl>
    <dl id="holder_license">
        <dt><span><?php echo $this->t('Agent License Number')?><a href="#" id="tips4">(Explain)</a></span> <a href="#" rel="profile_license" class="change" id="change_license"><?php echo $this->t('Change')?></a><a href="#" rel="profile_license" class="change" id="hide_license" style="display:none;"><?php echo $this->t('Hide')?></a> </dt>
        <dd class="info"><span><?php echo $this->t('Your Property Agent License ')?></span><em id="profile_license_name">
                <?php if (empty($this->loggedin_user->license_id)) { echo $this->t('No Information'); } else { echo $this->loggedin_user->license_id; }?></em></dd>
        <dd style="display:none;" id="profile_license">
            <form  id="profile_license_form">
                <fieldset>
                    <div class="text" class="required">
                        <label><?php echo $this->t('Your Property Agent License #')?></label>
                        <input type="text" name="license" id="profile_license_value" value="<?php echo $this->loggedin_user->license_id?>">
                        <ul class="errors" style="display:none;" id="li_error"><li><?php echo $this->t('Numbers Only')?></li></ul>
                    </div>
                    <div class="button em"><button><?php echo $this->t('Update')?></button></div>
                </fieldset>
            </form>
        </dd>
    </dl>

    <dl id="holder_services">
        <dt><span><?php echo $this->t('Specialities & Services')?><a href="#" id="tips2">(Explain)</a></span> <a href="#" rel="profile_services" class="change" id="change_services"><?php echo $this->t('Change')?></a><a href="#" rel="profile_services" class="change" id="hide_services" style="display:none;"><?php echo $this->t('Hide')?></a> </dt>
        <dd class="info"><span><?php echo $this->t('Services You Offer')?></span><em id="profile_services_name"><?php echo empty($this->loggedin_user->services)?$this->t('No Information'):$this->loggedin_user->services?></em></dd>
        <dd style="display:none;" id="profile_services">
            <form id="profile_services_form">
                <fieldset>
                    <div class="text">
                        <label><?php echo $this->t('Services you offer')?></label>
                        <input type="text" name="services" id="profile_services_value" value="<?php echo $this->loggedin_user->services?>">
                    </div>
                    <div class="button em"><button><?php echo $this->t('Update')?></button></div>
                </fieldset>
            </form>
        </dd>
    </dl>
    
</section>
